import { createStore } from "vuex";
import {
  getRecommendApi,
  getHospitalApi,
  getAdussApi,
  getathomeApi,
  gethealthshopApi,
  gethealshopstoreApi,
  getdetailImgApi,
  getMessageApi,
} from "../utils/api";

export default createStore({
  state: {
    cityname: localStorage.getItem("name") || "健康杭州",
    recommend: [],
    doctorinfo: [],
    hospital: [],
    aduss: [],
    athomelist: [],
    // athomelisttwo: [],
    healshopbarginlist: [],
    healshopstorelist: [],
    detaillist: [],
    getMessagelist: [],
  },
  mutations: {
    cityname(state, value) {
      state.cityname = value.text;
      localStorage.setItem("name", value.text);
    },
    setRecommend(state, res) {
      state.recommend = res.list;
    },
    setHospital(state, res) {
      state.hospital = res.list;
    },
    setadusstal(state, res) {
      state.aduss = res.list;
    },
    changeathome(state, payload) {
      state.athomelist = payload.list;
      // state.athomelisttwo=payload.list.slice(0,2)
    },
    changeindex(state, payload) {
      state.athomelisttwo = state.athomelist.slice(payload, payload + 2);
    },
    changehealshopbargin(state, payload) {
      state.healshopbarginlist = payload.list;
    },
    changhealshopstore(state, payload) {
      if (payload.status === 0) {
        state.healshopstorelist = payload.list;
      }
    },
    changedetailImg(state, payload) {
      if (payload.status === 0) {
        state.detaillist = payload.list;
      }
    },
    getdoctorInfo(state, payload) {
      state.doctorinfo = payload.list;
    },
    getOnlinelist(state, payload) {
      if (payload.status === 0) {
        state.getMessagelist = payload.list;
      }
    },
    changeprice(state, payload) {
      state.detaillist[0].newprice = payload * state.detaillist[0].price;
    },
  },
  actions: {
    //寻医说
    async getRecommend({ commit }, a) {
      const res = await getRecommendApi({
        indications: a,
      });
      commit("setRecommend", res);
    },
    //名医工作室
    async getHospital({ commit }) {
      const res = await getHospitalApi({
        wang: "jia",
      });
      commit("setHospital", res);
    },
    //医院列表
    async getadusstal({ commit }) {
      const res = await getAdussApi();
      commit("setadusstal", res);
    },
    async changeathomeApi({ commit }) {
      const res = await getathomeApi();
      commit("changeathome", res);
    },
    async changehealshopAsync({ commit }) {
      const res = await gethealthshopApi();
      commit("changehealshopbargin", res);
    },
    async changehealshopstoreAsync({ commit }) {
      const res = await gethealshopstoreApi();
      commit("changhealshopstore", res);
    },
    async getdetaillistAsync({ commit }, payload) {
      const res = await getdetailImgApi(payload);
      commit("changedetailImg", res);
      // 首页医生信息
    },

    async changeDoctorInfoAsync({ commit }) {
      const res = await getRecommendApi();
      commit("getdoctorInfo", res);
    },

    async getOnlinelistAsync({ commit }) {
      const res = await getMessageApi();
      commit("getOnlinelist", res);
    },
  },
  modules: {},
});
